<template>
    <div>
        <!--卡片-->
        <el-card class="box-card">
            <!--定义面包屑-->
            <el-breadcrumb separator=">">
                <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>系统管理</el-breadcrumb-item>
                <el-breadcrumb-item>用户管理</el-breadcrumb-item>
            </el-breadcrumb>
            <el-divider></el-divider>
            <!--表单的搜索框杀杀杀
                 :model="双向绑定表单的数据"
            -->
            <el-form :inline="true" :model="carTypeFormData"  class="demo-form-inline">
                <el-form-item >
                    <el-input v-model="carTypeFormData.name" placeholder="请输入品牌"></el-input>
                </el-form-item>
                <!--                <el-form-item >-->
                <!--                    <el-input v-model="userFormData.loginName" placeholder="请输入昵称"></el-input>-->
                <!--                </el-form-item>-->
                <!--                <el-form-item >-->
                <!--                    <el-input v-model="userFormData.email" placeholder="请输入邮箱"></el-input>-->
                <!--                </el-form-item>-->
                <!--                <el-form-item >-->
                <!--                    <el-input v-model="userFormData.phone" placeholder="请输入电话"></el-input>-->
                <!--                </el-form-item>-->
                <el-form-item>
                    <el-button type="primary" @click="chaxun">查询</el-button>
                    <el-button type="primary" @click="insert">添加</el-button>
                </el-form-item>
            </el-form>

            <!--数据表格-->
            <template>
                <el-table
                        :data="tableData"
                        :border="true"
                        stripe
                        style="width: 100%">
                    <el-table-column
                            prop="id"
                            label="编号"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="name"
                            label="品牌名字"
                            width="180">
                    </el-table-column>

                    <el-table-column
                            prop="firstLetter"
                            label="首字母"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="sort"
                            label="排序等级"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="factoryStatus"
                            :formatter="zhuangtaima"
                            label="是否为品牌制造商"
                            width="180">
                    </el-table-column>
<!--                    <el-table-column-->
<!--                            prop="showStatus"-->
<!--                            label="品牌状态"-->
<!--                            width="180">-->
<!--                    </el-table-column>-->
<!--                    <el-table-column-->
<!--                            prop="logo"-->
<!--                            label="品牌logo"-->
<!--                            width="180">-->
<!--                    </el-table-column>-->
<!--                    <el-table-column-->
<!--                            prop="bigPic"-->
<!--                            label="专区大图"-->
<!--                            width="180">-->
<!--                    </el-table-column>-->
                    <el-table-column
                            prop="brandStory"
                            label="品牌故事"
                            width="180">
                    </el-table-column>


                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <el-button type="primary" icon="el-icon-edit" circle @click="selectById(scope.row.id)"></el-button>
                            <el-button type="danger" icon="el-icon-delete" circle @click="deleteById(scope.row.id)"></el-button>
                            <!--                            <el-button type="warning" icon="el-icon-star-off" circle @click="showUserRole(scope.row.userId)"></el-button>-->
                        </template>
                    </el-table-column>
                </el-table>

                <!--                分页-->
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="currentPage"
                        :page-sizes="[5, 10, 15, 20]"
                        :page-size="pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </template>
        </el-card>

        <el-dialog
                title="提示"
                :visible.sync="editDialogVisible"
                width="30%"
        >
            <!--            model:表单数据-->
            <el-form  label-width="130px" :model="carTypeForm" >
                <el-form-item label="id" style="display: none">
                    <el-input v-model="carTypeForm.id" ></el-input>
                </el-form-item>
                <el-form-item :error="errorMsg"  label="品牌名字" >
                    <el-input v-model="carTypeForm.name" @blur="selectByName"></el-input>
                </el-form-item>
                <el-form-item label="首字母">
                    <el-select v-model="carTypeForm.firstLetter" placeholder="请选择">
                        <el-option
                                v-for="itemes in letter"
                                :key="itemes"
                                :label="itemes"
                                :value="itemes"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="是否为品牌制造商" >
                    <el-radio v-model="carTypeForm.factoryStatus" :label="0">No</el-radio>
                    <el-radio v-model="carTypeForm.factoryStatus" :label="1">Yes</el-radio>
                </el-form-item>
                <el-form-item label="排序等级" >
                    <el-input v-model="carTypeForm.sort"></el-input>
                </el-form-item>
<!--                <el-form-item label="专区大图" >-->
<!--                    <el-input v-model="carTypeForm.bigPic"></el-input>-->
<!--                </el-form-item>-->
                <el-form-item label="品牌故事" >
                    <el-input v-model="carTypeForm.brandStory"></el-input>
                </el-form-item>

            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editDialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="formSubmit">确 定</el-button>
              </span>
        </el-dialog>

    </div>
</template>

<script>
    export default {
        name: "CarBrand",
        data(){
            return {
                editDialogVisible:false,
                //条件搜索对象
                carTypeFormData:{},
                //表格数据
                tableData:[],
                //每页显示的条数
                pageSize: 5,
                //当前的显示的页码
                currentPage:1,
                //总条数
                total:0,
                carTypeForm:{},
                letter:['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'],
                errorMsg:""


            }
        },
        created() {
            this.selectall();
        },
        methods:{
            selectByName(){
                var that=this;
               this.$http.post("rents/brand/selectByName",this.carTypeForm).then(function (returnResult) {
                     that.errorMsg=returnResult.data.message;
               })
            },
            formSubmit(){
                var that=this;
                if(this.carTypeForm.id!=null){
                    this.$http.put("rents/brand/update",this.carTypeForm).then(function (returnResult) {
                        that.editDialogVisible=false;
                        that.carTypeForm={};
                        that.selectall();
                    })
                }else {
                    this.$http.post("rents/brand/insert", this.carTypeForm).then(function (returnResult) {
                        that.editDialogVisible = false;
                        that.selectall();
                    })
                }

            },
            selectall(){
                var that=this;
                this.$http.post(`rents/brand/pageSelect/${this.currentPage}/${this.pageSize}`,this.carTypeFormData).then(function (returnResult) {
                    that.total=returnResult.data.result.total;
                    that.tableData=returnResult.data.result.records;
                    console.log(that.tableData)

                })
            },
            chaxun(){
                this.selectall();
            },
            insert(){
                this.editDialogVisible=true;
                this.carTypeForm={};
            },
            deleteById(id){
                var that=this;
                this.$http.delete("rents/brand?id="+id).then(function (returnResult) {
                    that.selectall();
                    alert("删除成功")
                })
            },
            selectById(id){
                var that=this;
                this.$http.get(`rents/brand/selectById/${id}`).then(function (returnResult) {
                    that.editDialogVisible=true;
                    console.log(returnResult)
                    that.carTypeForm=returnResult.data.result.huixian;
                    console.log(returnResult)
                })
            },
            handleSizeChange(v){
                this.pageSize=v;
                this.selectall();
            },
            handleCurrentChange(v){
                this.currentPage=v;
                this.selectall();
            },
            zhuangtaima(row,column){
                var status=row.factoryStatus;
                if(status==1){
                    return '是'
                }
                if(status==0){
                    return '不是'
                }

            }

        }
    }
</script>

<style scoped>

</style>